package com.dianrui.qiyouriding.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.dianrui.qiyouriding.R;
import com.dianrui.qiyouriding.bean.DepositCoupon;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 限时活动优惠券适配器
 * Created by yis on 2018/4/17.
 */

public class DespoitCouponAdapter extends BaseAdapter {

    private List<DepositCoupon> data;
    private Context mContext;

    DespoitCouponClickListener despoitCouponClickListener;

    public DespoitCouponAdapter(Context mContext, List<DepositCoupon> data) {
        this.mContext = mContext;
        this.data = data;

    }

    public void refresh(List<DepositCoupon> list) {
        this.data = list;
        this.notifyDataSetChanged();
    }


    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    public interface DespoitCouponClickListener {
        void onDespoitCouponClick(int postion, String total);

    }

    public void setOnButtonClickListener(DespoitCouponClickListener despoitCouponClickListener) {
        this.despoitCouponClickListener = despoitCouponClickListener;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView != null) {
            holder = (ViewHolder) convertView.getTag();
        } else {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.coupon_item, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }
        if (data != null && data.size() > 0) {
            DepositCoupon coupon = data.get(position);
            holder.name.setText(coupon.name);
            holder.describe.setText(coupon.describe);
            holder.sellPrice.setText(coupon.sell_price+"元");

            if (TextUtils.isEmpty(coupon.activity)) {
                holder.activity.setVisibility(View.GONE);
            }else {
                holder.activity.setVisibility(View.VISIBLE);
                holder.activity.setText(coupon.activity);
            }
            if (TextUtils.isEmpty(coupon.total)) {
                holder.total.setVisibility(View.GONE);
            }else {
                holder.total.setText("原价"+coupon.total+"元");
                holder.total.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);//添加删除线
            }

        }
        return convertView;
    }


     class ViewHolder {
        @BindView(R.id.name)
        TextView name;
        @BindView(R.id.describe)
        TextView describe;
         @BindView(R.id.activity)
         TextView activity;
        @BindView(R.id.sell_price)
        TextView sellPrice;
        @BindView(R.id.total)
        TextView total;
        @BindView(R.id.click_coupen_layout)
        LinearLayout clickCoupenLayout;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
